package hai.wom.org.qyer_home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import hai.wom.org.qyer_home.R;
import hai.wom.org.qyer_home.bean.GuessLike;

/**
 * Created by Administrator on 2017/1/11 0011.
 */

public class MyAdapter_MainActivity extends BaseAdapter {
List<GuessLike.DataEntity> list;
    Context context;

    public MyAdapter_MainActivity(List<GuessLike.DataEntity> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_guesslike,parent,false);
            holder=new ViewHolder();
            holder.iv= (ImageView) convertView.findViewById(R.id.iv_item_guesslike);
            holder.tv1= (TextView) convertView.findViewById(R.id.tv_headline_guesslike);
            holder.tv2= (TextView) convertView.findViewById(R.id.tv_number_guesslike);
            holder.tv3= (TextView) convertView.findViewById(R.id.tv_money_guesslike);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }

        GuessLike.DataEntity dataEntity=list.get(position);
        holder.tv1.setText(dataEntity.getTitle());
        holder.tv2.setText(dataEntity.getSale_count()+"件已售");
        holder.tv3.setText(dataEntity.getPrice());
        Picasso.with(context).load(dataEntity.getPic()).into(holder.iv);


        return convertView;
    }


    class ViewHolder{
        ImageView iv;
        TextView tv1,tv2,tv3;
    }
}
